<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<title>
PRISM Manual | PropertySpecification / Filters 
</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="keywords" content="prism, probabilistic, symbolic, model, checker, verification, birmingham, oxford, parker, norman, kwiatkowska">

<link rel="icon" href="../pub/skins/offline/images/p16.ico" type="image/x-icon">
<link rel="shortcut icon" href="../pub/skins/offline/images/p16.ico" type="image/x-icon">

<!--HTMLHeader--><style type='text/css'><!--
  ul, ol, pre, dl, p { margin-top:0px; margin-bottom:0px; }
  code.escaped { white-space: nowrap; }
  .vspace { margin-top:1.33em; }
  .indent { margin-left:40px; }
  .outdent { margin-left:40px; text-indent:-40px; }
  a.createlinktext { text-decoration:none; border-bottom:1px dotted gray; }
  a.createlink { text-decoration:none; position:relative; top:-0.5em;
    font-weight:bold; font-size:smaller; border-bottom:none; }
  img { border:0px; }
  .editconflict { color:green; 
  font-style:italic; margin-top:1.33em; margin-bottom:1.33em; }

  table.markup { border:2px dotted #ccf; width:90%; }
  td.markup1, td.markup2 { padding-left:10px; padding-right:10px; }
  table.vert td.markup1 { border-bottom:1px solid #ccf; }
  table.horiz td.markup1 { width:23em; border-right:1px solid #ccf; }
  table.markup caption { text-align:left; }
  div.faq p, div.faq pre { margin-left:2em; }
  div.faq p.question { margin:1em 0 0.75em 0; font-weight:bold; }
  div.faqtoc div.faq * { display:none; }
  div.faqtoc div.faq p.question 
    { display:block; font-weight:normal; margin:0.5em 0 0.5em 20px; line-height:normal; }
  div.faqtoc div.faq p.question * { display:inline; }
   
    .frame 
      { border:1px solid #cccccc; padding:4px; background-color:#f9f9f9; }
    .lfloat { float:left; margin-right:0.5em; }
    .rfloat { float:right; margin-left:0.5em; }
a.varlink { text-decoration:none; }

.sourceblocklink {
  text-align: right;
  font-size: smaller;
}
.sourceblocktext {
  padding: 0.5em;
  border: 1px solid #808080;
  color: #000000;
  background-color: #f1f0ed;
}
.sourceblocktext div {
  font-family: monospace;
  font-size: small;
  line-height: 1;
  height: 1%;
}
.sourceblocktext div.head,
.sourceblocktext div.foot {
  font: italic medium serif;
  padding: 0.5em;
}

--></style>  <meta name='robots' content='index,follow' />


<link type="text/css" rel="stylesheet" href="../pub/skins/offline/css/base.css">
<link type="text/css" rel="stylesheet" href="../pub/skins/offline/css/prism.css">
<link type="text/css" rel="stylesheet" href="../pub/skins/offline/css/prismmanual.css">

</head>

<body text="#000000" bgcolor="#ffffff">

<div id="layout-maincontainer">
<div id="layout-main">

<div id="prism-mainbox">

<!-- ============================================================================= -->

<!--PageHeaderFmt-->
<!--/PageHeaderFmt-->

<!--PageTitleFmt-->
  <div id="prism-man-title">
    <p><a class='wikilink' href='Introduction.html'>Property Specification</a> /
</p><h1>Filters</h1>

  </div>
<!--PageText-->
<div id='wikitext'>
<p>As discussed above, when reporting the result of model checking a property, PRISM will by default return the value for the (single) initial state of the model. However, since PRISM in fact usually has to compute values for <em>all</em> states simultaneously, you can customise PRISM properties to obtain different results. This is done using <em>filters</em>.
</p>
<p class='vspace'>Filters are created using the <code>filter</code> keyword. They take the following form:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock1'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">op</span>, <span class="prismident">prop</span>, <span class="prismident">states</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=1' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>where <code>op</code> is the filter <em>operator</em> (see below), <code>prop</code> is any PRISM property and <code>states</code> is a Boolean-valued expression identifying a set of states over which to apply the filter.
</p>
<p class='vspace'>In fact, the <code>states</code> argument is optional; if omitted, the filter is applied over all states. So, the following properties are equivalent:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock2'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">op</span>, <span class="prismident">prop</span>)<br/>
<span class="prismkeyword">filter</span>(<span class="prismident">op</span>, <span class="prismident">prop</span>, <span class="prismkeyword">true</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=2' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>Here's a simple example of a filter:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock3'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismkeyword">max</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], <span class="prismident">x</span>=<span class="prismnum">0</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=3' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>This gives the <em>maximum</em> value, starting from any state satisfying <code>x=0</code>, of the probability of reaching an "error" state.
</p>
<p class='vspace'>Here's another simple example,
which checks whether, <em>starting from any reachable state</em>,
we eventually reach a "done" state with probability 1.
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock4'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">forall</span>, <span class="prismkeyword">P</span>&gt;=<span class="prismnum">1</span> [ <span class="prismkeyword">F</span> "<span class="prismident">done</span>" ])<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=4' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>We could modify this property slightly to instead check whether, from any state that satisfies the label "ready", we eventually reach a "done" state with probability 1. This could be done with either of the following two equivalent properties:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock5'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">forall</span>, "<span class="prismident">ready</span>" =&gt; <span class="prismkeyword">P</span>&gt;=<span class="prismnum">1</span> [ <span class="prismkeyword">F</span> "<span class="prismident">done</span>" ])<br/>
<span class="prismkeyword">filter</span>(<span class="prismident">forall</span>, <span class="prismkeyword">P</span>&gt;=<span class="prismnum">1</span> [ <span class="prismkeyword">F</span> "<span class="prismident">done</span>" ], "<span class="prismident">ready</span>")<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=5' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'><strong>Note:</strong> In older versions of PRISM, the property above could be written just as <code>"ready" =&gt; P&gt;=1 [ F "done" ]</code> since the result was checked for all states by default, not just the <a class='wikilink' href='SyntaxAndSemantics.html'>initial state</a>. Now, you need to explicitly include a filter, as shown above, to achieve this.
</p>
<div class='vspace'></div><h3>Types of filter</h3>
<p>Most filters of the form <code>filter(op, prop, states)</code>
apply some operator <code>op</code> to the values of property <code>prop</code>
for all the states satisfying <code>states</code>,
resulting in a single value.
The full list of filter operators <code>op</code> in this category is:
</p>
<div class='vspace'></div><ul><li><code>min</code>: the minimum value of <code>prop</code> over states satisfying <code>states</code>
</li><li><code>max</code>: the maximum value of <code>prop</code> over states satisfying <code>states</code>
</li><li><code>count</code>: cousnts the number of states satisfying <code>states</code> for which <code>prop</code> is true
</li><li><code>sum</code> (or <code>+</code>): sums the value of <code>prop</code> for states satisfying <code>states</code>
</li><li><code>avg</code>: the average value of <code>prop</code> over states satisfying <code>states</code>
</li><li><code>first</code>: the value of <code>prop</code> for the first (lowest-indexed) state satisfying <code>states</code>
</li><li><code>range</code>: the range (interval) of values of <code>prop</code> over states satisfying <code>states</code>
</li><li><code>forall</code> (or <code>&amp;</code>): returns <code>true</code> if <code>prop</code> is <code>true</code> for all states satisfying <code>states</code>
</li><li><code>exists</code> (or <code>|</code>): returns <code>true</code> if <code>prop</code> is <code>true</code> for some states satisfying <code>states</code>
</li><li><code>state</code>: returns the value for the single state satisfying <code>states</code> (if there is more than one, this is an error)
</li></ul><p class='vspace'>There are also a few filters that, rather than returning a single value, return different values for each state, like a normal PRISM property:
</p>
<div class='vspace'></div><ul><li><code>argmin</code>: returns <code>true</code> for the states satisfying <code>states</code> that yield the minimum value of <code>prop</code>
</li><li><code>argmax</code>: returns <code>true</code> for the states satisfying <code>states</code> that yield the maximum value of <code>prop</code>
</li><li><code>print</code>: does not change the result of <code>prop</code> but prints the values to the log
</li></ul><div class='vspace'></div><h3>More examples</h3>
<p>Here are some further illustrative examples of properties that use filters.
</p>
<p class='vspace'>Filters provide a quick way to <em>print</em> the results of a model checking query for several states. In most cases, for example, a <code>P=?</code> query just returns the probability from the initial state. To see the probability for all states satisfying <code>x&gt;2</code>, use:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock6'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">print</span>, <span class="prismkeyword">P</span>=? [ ... ], <span class="prismident">x</span>&gt;<span class="prismnum">2</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=6' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>Values are printed in the log (i.e. to the "Log" tab in the GUI or to the terminal from the command-line). For small models, you could omit the final <code>states</code> argument (<code>x&gt;2</code> here) and view the probabilities from all states. You can also use PRISM's <a class='wikilink' href='../ConfiguringPRISM/OtherOptions.html'>verbose</a> mode to view values for all states, but filters provide an easier and more flexible solution.
<code>print</code> filters do not actually alter the result returned so, in the example above, PRISM will still return the probability for the initial state, in addition to printing other probabilities in the log.
</p>
<p class='vspace'>You can also use <code>print</code> filters to display lists of states. For example, this property:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock7'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">print</span>, <span class="prismkeyword">filter</span>(<span class="prismident">argmax</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ]))<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=7' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>prints the states which have the highest probability of reaching an error state.
However, you should exercise caution when using <code>argmax</code> (or <code>argmin</code>) on properties such as <code>P=? [ ... ]</code> (or <code>S=? [ ... ]</code> or <code>R=? [ ... ]</code>), whose results are only approximate due to the nature of the methods used to compute them (or because of round-off errors.)
</p>
<p class='vspace'>Another common use of filters is to display the value for a particular state of the model (rather than the initial state, which is used by default). To achieve this, use e.g.:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock8'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">state</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], <span class="prismident">x</span>=<span class="prismnum">2</span>&amp;<span class="prismident">y</span>=<span class="prismnum">3</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=8' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>where <code>x=2&amp;y=3</code> is assumed to specify one particular state.
A <code>state</code> filter will produce an error if the filter expression is not satisfied by exactly one state of the model.
</p>
<p class='vspace'>Filters can also be built up into more complex expressions. For example, the following two properties are equivalent:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock9'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">avg</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], "<span class="prismkeyword">init</span>")<br/>
<span class="prismkeyword">filter</span>(<span class="prismident">sum</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], "<span class="prismkeyword">init</span>") / <span class="prismkeyword">filter</span>(<span class="prismident">count</span>, "<span class="prismkeyword">init</span>")<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=9' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>The <code>range</code> filter, unlike most PRISM expressions which are of type Boolean, integer or double, actually returns an interval: a pair of integers or doubles. For example:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock10'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">range</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> <span class="prismident">count</span>=<span class="prismnum">10</span> ], <span class="prismident">count</span>=<span class="prismnum">0</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=10' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>gives the range of all possible values for the probability of reach a state satisfying <code>count=10</code>, from all states satisfying <code>count=0</code>.
As will be described below, this kind of property also results from the use of old-style (<code>{...}</code>) filters and properties on models with multiple initial states.
</p>
<div class='vspace'></div><h3>Old-style filters</h3>
<p>In older versions of PRISM, filters were also available, but in a less expressive form. Previously, they were only usable on <code><strong>P</strong></code>, <code><strong>S</strong></code> or <code><strong>R</strong></code> properties and only a small set of filter operators were permitted. They were also specified in a different way, using braces (<code>{</code>...<code>}</code>). For compatibility with old properties files (and for compactness), these forms of filters are still allowed. These old-style forms of filters:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock11'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> {<span class="prismident">states</span>} ]<br/>
<span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> {<span class="prismident">states</span>}{<span class="prismkeyword">min</span>} ]<br/>
<span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> {<span class="prismident">states</span>}{<span class="prismkeyword">max</span>} ]<br/>
<span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> {<span class="prismident">states</span>}{<span class="prismkeyword">min</span>}{<span class="prismkeyword">max</span>} ]<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=11' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>are equivalent to:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock12'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">state</span>, <span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> ], <span class="prismident">states</span>)<br/>
<span class="prismkeyword">filter</span>(<span class="prismkeyword">min</span>, <span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> ], <span class="prismident">states</span>)<br/>
<span class="prismkeyword">filter</span>(<span class="prismkeyword">max</span>, <span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> ], <span class="prismident">states</span>)<br/>
<span class="prismkeyword">filter</span>(<span class="prismident">range</span>, <span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> ], <span class="prismident">states</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=12' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>Notice that the first of the four properties above (i.e. an old-style filter of the form <code>{states}</code> will result in an error if <code>states</code> is not satisfied by exactly one state of the model. Older versions of PRISM just gave you the value for the first state state satisfying the filter, without warning you about this. If you want to recreate the old behaviour, just use a <code>first</code> filter:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock13'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">first</span>, <span class="prismkeyword">P</span>=? [ <span class="prismident">pathprop</span> ], <span class="prismident">states</span>)<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=13' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<div class='vspace'></div><h3>Default filters</h3>
<p>Finally, for completeness, we show what the <em>default</em> filters are in PRISM,
i.e. how the way that PRISM returns values from properties by default
could have been achieved equivalently using filters.
</p>
<p class='vspace'>Queries of the form:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock14'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">P</span>&gt;<span class="prismnum">0.5</span> [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ]<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=14' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>are the same as:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock15'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">forall</span>, <span class="prismkeyword">P</span>&gt;<span class="prismnum">0.5</span> [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], "<span class="prismkeyword">init</span>")<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=15' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>and queries of the form:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock16'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ]<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=16' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>are the same as either:
</p>
<div class='vspace'></div>
<div class='sourceblock ' id='sourceblock17'>
  <div class='sourceblocktext'><div class="prism"><span class="prismkeyword">filter</span>(<span class="prismident">state</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], "<span class="prismkeyword">init</span>")<br/>
<span class="prismkeyword">filter</span>(<span class="prismident">range</span>, <span class="prismkeyword">P</span>=? [ <span class="prismkeyword">F</span> "<span class="prismident">error</span>" ], "<span class="prismkeyword">init</span>")<br/>
</div></div>
  <div class='sourceblocklink'><a href='Filters@action=sourceblock&amp;num=17' type='text/plain'>[&#036;[Get Code]]</a></div>
</div>

<p class='vspace'>for the cases where there the model has a single initial state
or multiple initial states, respectively.
</p>
</div>


<!--PageFooterFmt-->
  <div id='prism-man-footer'>
  </div>
<!--/PageFooterFmt-->


<!-- ============================================================================= -->

</div> <!-- id="prism-mainbox" -->

</div> <!-- id="layout-main" -->
</div> <!-- id="layout-maincontainer" -->

<div id="layout-leftcol">
<div id="prism-navbar2">

<h3><a class='wikilink' href='../Main/Welcome.html'>PRISM Manual</a></h3>
<p><strong><a class='wikilink' href='Introduction.html'>Property Specification</a></strong>
</p><ul><li><a class='wikilink' href='Introduction.html'>Introduction</a>
</li><li><a class='wikilink' href='IdentifyingASetOfStates.html'>Identifying A Set Of States</a>
</li><li><a class='wikilink' href='ThePOperator.html'>The P Operator</a>
</li><li><a class='wikilink' href='TheSOperator.html'>The S Operator</a>
</li><li><a class='wikilink' href='Reward-basedProperties.html'>Reward-based Properties</a>
</li><li><a class='wikilink' href='SyntaxAndSemantics.html'>Syntax And Semantics</a>
</li><li><a class='selflink' href='Filters.html'>Filters</a>
</li><li><a class='wikilink' href='PTAProperties.html'>PTA Properties</a>
</li><li><a class='wikilink' href='PropertiesFiles.html'>Properties Files</a>
</li></ul><p>[ <a class='wikilink' href='AllOnOnePage.html'>View all</a> ]
</p>


</div>  <!-- id="prism-navbar2" -->
</div> <!-- id="layout-leftcol" -->

</body>
</html>
